package com.example.test.controller;

import com.example.test.entity.Log;
import com.example.test.entity.Look;
import com.example.test.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api/log")
@RestController
@CrossOrigin
public class LogController {
    @Autowired
    private LogService logService;
    @GetMapping
    public ResponseEntity<List<Log>> getAllLogs() {
        List<Log> allLogs = logService.getAllLogs();
        return ResponseEntity.ok().body(allLogs);
    }
    @PostMapping("/logmes")
    public ResponseEntity<?> recordLog(@RequestBody Log log) {
        int result = logService.createLog(log);
        if (result == 1) {
            return ResponseEntity.ok().build();
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }

}
